import Vue from 'vue'
import Vuex from 'vuex'
import request from '../utils/request'

Vue.use(Vuex)

export default new Vuex.Store({
    state: {
        userInfo: {
            id:'',
            info:{},
            level:'',
        },
        isLogin: false,
        tenantInfo: {},
        goodsInfo: {},
        params:{ 
        },
        showOtherSite: true,//true显示分站搭建，false不显示
        showMeAd:true,//true显示会员中心发B网广告，false不显示
    },
    mutations: {
        getGoodsInfo(state,obj){
            state.goodsInfo = obj
        },
        getUserInfo(state,obj){
            state.userInfo.id = obj.id;
            state.userInfo.info = obj.info;
            state.userInfo.level = obj.level;
        },
        setIsLogin(state,value){
            state.isLogin = value
        },
        getTenantInfo(state){
            request.post({
                url:'/ReportApi/business/tenantinfo',
                params:{
                    locations:location.hostname
                },
                success: res => {
                    state.tenantInfo = res;
                    localStorage.setItem("tenantInfoid", res.id);
                    //consloe.log(res)
                },
                finally: () => {
                }
            })
        },
        getParams(state){
            request.post({
                url:'/ReportApi/business/showparams',
                params:{},
                success: res => {
                    state.params = res;
                    var hostName = window.location.host;
                    if(res.no_show_other_site.indexOf(hostName)!=-1){
                        state.showOtherSite = false;
                    }
                    if(res.no_show_me_ad.indexOf(hostName)!=-1){
                        state.showMeAd = false;
                    }
                },
                finally: () => {
                }
            })
        }
    },
    actions: {

    },
    modules: {
    }
})
